home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Leser 15 / Amiga Plus Leser CD 15.iso / Tools / Development / MosaicSRC / src / spinner.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-03-13  |  5.7 KB  |  226 lines

  1. /********************************************************************
  2.  
  3. Spinner gadget for the interrupt button, by Michael Fischer 1994.
  4.  
  5. This will initially have a line radiating from the center of the
  6. gadget at 0, 45, 90, ... degree angles.
  7.  
  8. Eventually it will use images, perhaps of a rotating Boing ball.
  9.  
  10. *********************************************************************/
  11.  
  12. /* We really don't need _all_ these... try to narrow it down some time */
  13.  
  14. #include "includes.h"
  15. #include "HTML.h"
  16. #include "mosaic.h"
  17. #include "globals.h"
  18. #include "htmlgad.h"
  19. #include "gui.h"
  20. #include "XtoI.h"
  21. #include "protos.h"
  22. #include "spinner.h"
  23.  
  24. struct SpinnerClData {
  25.   int state;
  26. };
  27.  
  28. #define REG(x) register __ ## x
  29. #define ASM    __asm
  30. #define SAVEDS __saveds
  31.  
  32. /*
  33. ** AskMinMax method will be called before the window is opened
  34. ** and before layout takes place. We need to tell MUI the
  35. ** minimum, maximum and default size of our object.
  36. */
  37.  
  38. static ULONG SpinnerClAskMinMax(Class *cl,Object *obj,struct MUIP_AskMinMax *msg)
  39. {
  40.   /*
  41.    ** let our superclass first fill in what it thinks about sizes.
  42.    ** this will e.g. add the size of frame and inner spacing.
  43.    */
  44.   
  45.   DoSuperMethodA(cl,obj,(Msg)msg);
  46.   
  47.   /*
  48.    ** now add the values specific to our object. note that we
  49.    ** indeed need to *add* these values, not just set them!
  50.    */
  51.   
  52.   msg->MinMaxInfo->MinWidth  += 10;
  53.   msg->MinMaxInfo->DefWidth  += 11;
  54.   msg->MinMaxInfo->MaxWidth  += 15;
  55.  
  56.   msg->MinMaxInfo->MinHeight += 10;
  57.   msg->MinMaxInfo->DefHeight += 15;
  58.   msg->MinMaxInfo->MaxHeight += 30;
  59.  
  60.   return(0);
  61. }
  62.  
  63.  
  64.  
  65. static ULONG SpinnerClRender(Class *cl, Object *obj, struct MUIP_Draw *msg)
  66. {
  67.   struct SpinnerClData *inst = INST_DATA(cl, obj);
  68.   int midx, midy, x, y;
  69.  
  70.   /*
  71.    ** let our superclass draw itself first, area class would
  72.    ** e.g. draw the frame and clear the whole region. What
  73.    ** it does exactly depends on msg->flags.
  74.    */
  75.   
  76.   DoSuperMethodA(cl,obj,(Msg)msg);
  77.  
  78.   midx = _mright(obj) - _mwidth(obj)/2;
  79.   midy = _mbottom(obj) - _mheight(obj)/2;
  80.   
  81.   switch (inst->state) {
  82.   case 0:
  83.     x = midx; y = _mtop(obj); break;
  84.   case 1:
  85.     x = _mright(obj); y = _mtop(obj); break;
  86.   case 2:
  87.     x = _mright(obj); y = midy; break;
  88.   case 3:
  89.     x = _mright(obj); y = _mbottom(obj); break;
  90.   case 4:
  91.     x = midx; y = _mbottom(obj); break;
  92.   case 5:
  93.     x = _mleft(obj); y = _mbottom(obj); break;
  94.   case 6:
  95.     x = _mleft(obj); y = midy; break;
  96.   case 7:
  97.     x = _mleft(obj); y = _mtop(obj); break;
  98.   }
  99.  
  100.   if (msg->flags & MADF_DRAWOBJECT) {
  101.     SetAPen(_rp(obj), _dri(obj)->dri_Pens[BACKGROUNDPEN]);
  102.     RectFill(_rp(obj), _mleft(obj), _mtop(obj), _mright(obj), _mbottom(obj));
  103.     SetAPen(_rp(obj), _dri(obj)->dri_Pens[TEXTPEN]);
  104.     Move(_rp(obj), midx, midy);
  105.     Draw(_rp(obj), x, y);
  106.   }
  107.  
  108.   else if (msg->flags & MADF_DRAWUPDATE) { /* called from our input method */
  109.     SetAPen(_rp(obj), _dri(obj)->dri_Pens[BACKGROUNDPEN]);
  110.     RectFill(_rp(obj), _mleft(obj), _mtop(obj), _mright(obj), _mbottom(obj));
  111.     SetAPen(_rp(obj), _dri(obj)->dri_Pens[TEXTPEN]);
  112.     Move(_rp(obj), midx, midy);
  113.     Draw(_rp(obj), x, y);
  114.   }
  115.  
  116.   return 0;
  117. }
  118.  
  119.  
  120. static ULONG SpinnerClSetup(Class *cl, Object *obj, Msg msg)
  121. {
  122.   if (!(DoSuperMethodA(cl, obj, (Msg)msg)))
  123.     return (FALSE);
  124.  
  125.   MUI_RequestIDCMP(obj, IDCMP_MOUSEBUTTONS);
  126.  
  127.   return (TRUE);
  128. }
  129.  
  130.  
  131. static ULONG SpinnerClCleanup(Class *cl, Object *obj, Msg msg)
  132. {
  133.   MUI_RejectIDCMP(obj, IDCMP_MOUSEBUTTONS);
  134.   return (DoSuperMethodA(cl, obj, (Msg)msg));
  135. }
  136.  
  137.  
  138. #define _between(a,x,b) ((x)>=(a) && (x)<=(b))
  139. #define _isinobject(x,y) (_between(_mleft(obj),(x),_mright(obj)) && _between(_mtop(obj),(y),_mbottom(obj)))
  140.  
  141.  
  142. static ULONG SpinnerClHandleInput(Class *cl, Object *obj, 
  143.                   struct MUIP_HandleInput *msg)
  144. {
  145.   if (!(DoSuperMethodA(cl, obj, (Msg)msg)))
  146.     return (FALSE);
  147.  
  148.   return(0);
  149. }
  150.  
  151.  
  152. static ULONG SpinnerClSet(Class *cl, Object *obj, Msg msg)
  153. {
  154.   struct SpinnerClData *inst = INST_DATA(cl, obj);
  155.  
  156.   (inst->state)++;
  157.   if (inst->state > 7) inst->state = 0;
  158.   MUI_Redraw(obj, MADF_DRAWOBJECT);
  159.  
  160.   return (DoSuperMethodA(cl, obj, msg));
  161. }
  162.  
  163.  
  164. /********************************************************
  165.   The main gadget handler routine
  166. ********************************************************/
  167. ASM ULONG SpinnerClDispatch(REG(a0) Class *cl, REG(a2) Object *obj,
  168.                 REG(a1) Msg msg)
  169. {
  170.   switch (msg->MethodID)
  171.     {
  172.     case MUIM_AskMinMax: return(SpinnerClAskMinMax(cl,obj,(APTR)msg));
  173.     case MUIM_Draw     : return(SpinnerClRender(cl,obj,(APTR)msg));
  174.     case MUIM_HandleInput: return(SpinnerClHandleInput(cl,obj,(APTR)msg));
  175.     case MUIM_Setup    : return(SpinnerClSetup(cl,obj,(APTR)msg));
  176.     case MUIM_Cleanup  : return(SpinnerClCleanup(cl,obj,(APTR)msg));
  177.     case OM_SET        : return(SpinnerClSet(cl,obj,(APTR)msg));
  178.     }
  179.   
  180.   return(DoSuperMethodA(cl,obj,msg));
  181. }
  182.  
  183.  
  184. /************************************************************
  185.   Initilize the Spinner class
  186. ************************************************************/
  187. Class *SpinnerClInit(void)
  188. {
  189.   APTR SuperClass;
  190.   Class *cl = NULL;
  191.  
  192.   /* Get a pointer to the MUI superclass. */
  193.  
  194.   if (!(SuperClass = MUI_GetClass(MUIC_Area)))
  195.     fail(NULL, "Superclass for spinner class not found.");
  196.  
  197.   /* Create the MUI spinner class */
  198.  
  199.   if (!(cl = MakeClass(NULL, NULL, SuperClass, sizeof(struct SpinnerClData), 0)))
  200.     {
  201.       MUI_FreeClass(SuperClass);
  202.       fail(NULL, "Failed to create spinner class.");
  203.     }
  204.  
  205.   /* Set the class dispatcher */
  206.  
  207.   cl->cl_Dispatcher.h_Entry = (APTR)SpinnerClDispatch;
  208.   cl->cl_Dispatcher.h_SubEntry = NULL;
  209.   cl->cl_Dispatcher.h_Data = NULL;
  210.  
  211.   return cl;
  212. }
  213.  
  214.  
  215. /*******************************************************
  216.   Free the Spinner class
  217.   IS THERE AN ERROR HERE BECAUSE SUPERCLASS IS NEVER FREED?
  218. *******************************************************/
  219. BOOL SpinnerClFree(Class *cl)
  220. {
  221.   FreeClass(cl);
  222.   return 0;
  223. }
  224.  
  225.  
  226.